import PersonalService from "../service/PersonalService";
import { ElMessage } from 'element-plus';
// import PersonalStore from "../store/PersonalStore";
// import { useRouter } from "vue-router";

export interface IPerson {
    AllPrivate(coachId:number,courseName:string,limit:number,page:number,callback:any):void;
    PersonalDel(coachId:number,courseName:string,limit:number,page:number,id:number,AllPrivateAll:any):void;
    AddPersonalTrainer(obj:object):void;
    CompilePersonalTrainer(id:number,obj:object):void;
    Displayed(id:number,DisplayedList:any):void;
    Inquire(name:string,limit:number,page:number,id:string,AllPrivateAll:any):void
}

//获取所有私教课程信息
export function PersonalHooks(): IPerson {
    // const store = PersonalStore()
    // const router = useRouter()
    function AllPrivate(coachId:number,courseName:string,limit:number,page:number,callback:any) {
        PersonalService.getPrivateEducationInformation(coachId,courseName,limit,page).then((res:any)=>{
                console.log(res.data.data)
         if(res.data.code==0){
            callback(res.data.data)
          } 
        }).catch((err:any)=>{
      console.log(err)
      })
        
    }
    //删除私教课程
    function PersonalDel(coachId:number,courseName:string,limit:number,page:number,id:number,AllPrivateAll:any){
       PersonalService.getPersonalDel(id).then((res:any)=>{
        console.log(id)
        if(res.data.code==0){
          AllPrivate(coachId,courseName,limit,page,AllPrivateAll)
        }
       }).catch((err:any)=>{
        ElMessage.error("请求失败")
    })
    }

    //添加私教课程
    function AddPersonalTrainer(obj:object){
      PersonalService.getAddPersonalTrainer(obj).then((res:any)=>{
        console.log(obj)
       if(res.data.code==0){
         ElMessage({ type: "success", message: res.data.msg })
        //  callback()
       }
      }).catch((err:any)=>{
       ElMessage.error("请求失败")
   })
   }
   //编辑私教课程
   function CompilePersonalTrainer(id:number,obj:object){
    PersonalService.getCompilePersonalTrainer(id,obj).then((res:any)=>{
      console.log(res)
     if(res.data.code==0){
       ElMessage({ type: "success", message: res.data.msg })
     }
    }).catch((err:any)=>{
     ElMessage.error("请求失败")
 })
 }


 //根据id查询私教信息回显
 function Displayed(id:number,DisplayedList:any){
  PersonalService.getDisplayed(id).then((res:any)=>{
   if(res.data.code==0){
    console.log(res.data.data)
    DisplayedList(res.data.data)
   }else{
     ElMessage(res.data.msg)
   }
  }).catch((err:any)=>{
   ElMessage.error("请求失败")
})
}
//私教课程根据教练和课程名称查询
function Inquire(name:string,limit:number,page:number,id:string,AllPrivateAll:any){
  PersonalService.getInquire(name,limit,page,id).then((res:any)=>{
   if(res.data.code==0){
    console.log(res.data.data)
    AllPrivateAll(res.data.data)
   }
  }).catch((err:any)=>{
   ElMessage.error("请求失败")
})
}

    return{
        AllPrivate,
        PersonalDel,
        AddPersonalTrainer,
        CompilePersonalTrainer,
        Displayed,
        Inquire,
    }
}